package com.web.controller;

import com.web.pojo.Result;
import com.web.pojo.User;
import com.web.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author web
 * @version 1.0
 * @date 2024/04/14 23:16
 */
@Slf4j
@RestController
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    private UserService userService;

    @PostMapping
    public Result register(@RequestBody User user) {
        log.info("员工注册 {}", user);
        Integer affectRows = userService.register(user);
        if (affectRows == 0) {
            return  Result.error("用户名或密码为null");
        } else if (affectRows == -1) {
            return Result.error("用户名已存在");
        }
        return Result.success("注册成功");
    }
}
